



import bpy
import idprop

import 全局控制.Node.插座.bl_插座基类 as 插件基类
from 全局控制.Node.节点数据类型 import bl_集合数据类型



class C_NodeSocket_物体集合(插件基类.C_NodeSocket_基类):
	bl_label = '物体集合'
	
	m_Value = bpy.props.StringProperty(name='渲染层')
	def __init__(self):
		super(C_NodeSocket_物体集合, self).__init__()
		
	def draw(self, context, layout, node, text):
		if self.is_linked :
			layout.label(text=self.m_Value)
		else:
			if bpy.data.collections.find(self.m_Value) >= 0 :
				layout.prop_search(self, "m_Value", bpy.data, "collections", text="层")
			else:
				布局 = layout.row()
				布局.prop(self, 'm_Value')
				布局.operator("node.update_node_create_collection").m_名称 = self.m_Value


	def f_get集合(self, name):
		if name == '':
			return None
		#print('f_get集合 = ', name)
		渲染层容器ID = bpy.data.collections.find(name)
		if 渲染层容器ID < 0:
			col = bpy.data.collections.new(name)
			bpy.context.scene.collection.children.link(col)
			#print(' col f_get集合 = ', col)
			return col

		#print(' bpy.data.collections = ', bpy.data.collections)
		渲染层容器 = bpy.data.collections[渲染层容器ID]
		return 渲染层容器
		
	def f_getData(self, key=-1):
		data = super(C_NodeSocket_物体集合, self).f_getData(key)
		#print('C_NodeSocket_物体集合 = ', key, data, self.m_Value)
		if data != None:
			typeName = type(data).__name__
			if typeName == 'Collection' :
				return data
			elif typeName == 'str' :
				return self.f_get集合(data)

		return self.f_get集合(self.m_Value)
			
		
		
	def f_setData(self, data):
		if super(C_NodeSocket_物体集合, self).f_setData(data) :
			self.m_Value = str(data)
		#pass











class C_Socket_集合(插件基类.C_Socket_基类):
	bl_label = '物体集合'
	
	def __init__(self):
		super(C_Socket_集合, self).__init__()
		
	def f_get集合(self, name):
		
		#print(' bpy.data.collections = ', bpy.data.collections)
		return 渲染层容器
		
	def f_getData(self, key=-1):
		return self.f_get集合(self.m_Value)
		
	






classes = (
	C_NodeSocket_物体集合,
	C_Socket_集合,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)
	pass	

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)
	pass
	



